package com.oo.app.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.oo.app.R;

/**
 * @创建者 赵聪
 * @描述 提现审核
 */

public class PutForwardExamineDialog extends Dialog {

    private Context context;
    private ClickListenerInterface clickListenerInterface;
    private String title;
    private String content;
    private String btnName;
    private boolean isCancel = false;

    public interface ClickListenerInterface {

        public void doConfirm();

        public void doCancel();
    }

    public PutForwardExamineDialog(Context context) {
        super(context, R.style.time_dialog);
        this.context = context;
    }

    public PutForwardExamineDialog(Context context, String title, String content, String btnName) {
        super(context, R.style.time_dialog);
        this.context = context;
        this.title = title;
        this.content = content;
        this.btnName = btnName;
    }

    public PutForwardExamineDialog(Context context, String title, String content, String btnName, boolean isCancel) {
        super(context, R.style.time_dialog);
        this.context = context;
        this.title = title;
        this.content = content;
        this.btnName = btnName;
        this.isCancel = isCancel;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        init();
    }

    public void init() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dialog_put_forward_examine, null);
        setContentView(view);

        Button tvConfirm = (Button) view.findViewById(R.id.btn_confirm);
        ImageView tvCancel = (ImageView) view.findViewById(R.id.iv_cancel);
        TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
        TextView tvContent = (TextView) view.findViewById(R.id.tv_content);

        if (!TextUtils.isEmpty(title)){
            tvTitle.setText(title);
        }
        if (!TextUtils.isEmpty(content)){
            tvContent.setText(content);
        }
        if (!TextUtils.isEmpty(btnName)){
            tvConfirm.setText(btnName);
        }

        if (isCancel){
            tvCancel.setVisibility(View.GONE);
        }

        tvConfirm.setOnClickListener(new clickListener());
        tvCancel.setOnClickListener(new clickListener());

        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
        lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
        dialogWindow.setAttributes(lp);
    }

    public void setClicklistener(ClickListenerInterface clickListenerInterface) {
        this.clickListenerInterface = clickListenerInterface;
    }

    private class clickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            int id = v.getId();
            switch (id) {
                case R.id.btn_confirm:
                    clickListenerInterface.doConfirm();
                    break;
                case R.id.iv_cancel:
                    clickListenerInterface.doCancel();
                    break;
            }
        }

    }

    ;

}
